<cfcomponent output="false">

	<cffunction name="Login" output="false" access="remote">
		<cfargument name="user" required="true" />
		
		<cfset var qValidate = "" />
		<cfset var validatedUser = "" />
				
			<cfquery username="#request.username#" password="#request.password#" name="qValidate" datasource="nwharvest">
				SELECT USERS.ID,EMAIL,PASSWORD,ADDRESS_ID,ROLE_ID,FNAME,LNAME,CAT_ID,ACTIVE,IS_DELETED,ADDRESS1,ADDRESS2,CITY,STATE_PROVINCE,POSTAL_CODE,COUNTRY,PHONE,FAX,ADDRESS_CAT_ID,USER_ORG_ID
				FROM Users
				LEFT JOIN Address ON Address.ID = Users.Address_ID
				WHERE Email = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.user.Email#">
				AND Password = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.user.Password#">
			</cfquery>


			
			<cfif qValidate.recordcount eq 1>
				<!--- login this user in --->
				<cfset validatedUser = createObject("component","VirtualFoodDrive.virtualfooddrive-inf.com.User") />
				
				<cfset validatedUser.ID = qValidate.ID />				
				<cfset validatedUser.EMAIL = qValidate.EMAIL />				
				<cfset validatedUser.PASSWORD = qValidate.PASSWORD />				
				<cfset validatedUser.ADDRESS_ID = qValidate.ADDRESS_ID />																
				<cfset validatedUser.ROLE_ID = qValidate.ROLE_ID />								
				<cfset validatedUser.FNAME = qValidate.FNAME />				
				<cfset validatedUser.LNAME = qValidate.LNAME />																
				<cfset validatedUser.CAT_ID = qValidate.CAT_ID />								
				<cfset validatedUser.ACTIVE = qValidate.ACTIVE />				
				<cfset validatedUser.IS_DELETED = qValidate.IS_DELETED />		
				
				<cfset validatedUser.ID = qValidate.ID />
				<cfset validatedUser.ADDRESS1 = qValidate.ADDRESS1 />
				<cfset validatedUser.ADDRESS2 = qValidate.ADDRESS2 />
				<cfset validatedUser.CITY = qValidate.CITY />
				<cfset validatedUser.STATE_PROVINCE = qValidate.STATE_PROVINCE />
				<cfset validatedUser.POSTAL_CODE = qValidate.POSTAL_CODE />
				<cfset validatedUser.COUNTRY = qValidate.COUNTRY />
				<cfset validatedUser.PHONE = qValidate.PHONE />
				<cfset validatedUser.FAX = qValidate.FAX />
				<cfset validatedUser.ADDRESS_CAT_ID = qValidate.ADDRESS_CAT_ID />
				<cfset validatedUser.USER_ORG_ID = qValidate.USER_ORG_ID />

				<cfloginuser name = "#validatedUser.EMAIL#" password="#validatedUser.PASSWORD#" roles="#validatedUser.ROLE_ID#" />

				<cfreturn validatedUser />
			<cfelse>
				<cfreturn arguments.user />
			</cfif>
			
	</cffunction>


</cfcomponent>